/**
 * 打开app展示页
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Image,
    AsyncStorage,
    Alert
} from 'react-native';
import Main from './Main/Main';
import Login from './Login';
import { NavigationActions } from 'react-navigation'
let dimension = require('Dimensions');
let width = dimension.get('window').width;
export default class First extends Component {
    constructor(props) {
        super(props);
        this.state = {
        };
    }
    static navigationOptions={
        header:null
    };
    componentDidMount() {
        this.timer = setTimeout(() => {
            this._asyncAppStatus();
        }, 1000);

        }

        _asyncAppStatus()
        {
            AsyncStorage.getItem('user')
                .then((data) => {
                    let user;
                    let Next;
                    if (data) {
                        user = JSON.parse(data);
                    }
                    if (user && user.accessToken) {
                         Next='Main';          //  便于开发，暂时先改成登录
                        // Next='Login'
                    }
                    else {
                        Next='Login'
                    }
                    // const { Reset } = this.props.navigation;
                    // let {navigator} = this.props;
                    // if (navigator) {
                    //     navigator.replace({
                    //         name: 'Main',
                    //         component: Next,
                    //     });
                    // }
                    // Reset(Next)
                    const resetAction=NavigationActions.reset({index:0,actions:[NavigationActions.navigate({routeName:Next})]});
                    this.props.navigation.dispatch(resetAction)
                })
        }

        componentWillUnmount()
        {
            this.timer && clearInterval(this.timer);
        }


        render()
        {
            let pic = {uri: 'http://bmob-cdn-9229.b0.upaiyun.com/2017/02/22/ac57e5b1403aadc4808de77b47b638a5.jpg'}
            return (
                <View style={styles.container}>
                    <Image source={pic} style={styles.imageStyleImg}/>

                    <Image source={require('../img/icon.png')} style={styles.imageStylePag}/>
                </View>
            );
        }
    }

    const
    styles = StyleSheet.create({
        container: {
            flex: 1,
        },
        imageStyleImg: {
            flex: 6,
            width: width,
            resizeMode: 'stretch'
        },
        imageStylePag: {
            flex: 1,
            width: width,
            resizeMode: 'stretch'
        }
    });
